package com.capinfo.entity;

import com.capinfo.base.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import javax.persistence.*;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;

/**
 * @author: sunbenjin
 * @date: 2020/2/29
 **/
@Table(name = "sys_dict")
@Data
@ToString
@EqualsAndHashCode
public class SysDict extends BaseEntity {
    @Id
    @GeneratedValue(generator="JDBC")
    private String id;

    @Column(name = "p_id")
    private String pId;

    @Column(name = "dict_value")
    private String dictValue;

    @Column(name = "dict_name")
    private String dictName;

    @Column(name = "dict_type")
    private String dictType;

    @Column(name = "dict_desc")
    private String dictDesc;

    @Column(name = "sort")
    private Integer sort;




    private SysDict parent;

    /**
     * 根据字段去重
     * @param keyExtractor
     * @param <T>
     * @return
     */
    public static <T>Predicate<T> distinctByKey(Function<? super T,Object > keyExtractor){
            Map<Object,Boolean> seen = new ConcurrentHashMap<>();
            return t->seen.putIfAbsent(keyExtractor.apply(t),Boolean.TRUE) == null;

    }


}
